package com.endoc.agingtools;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.endoc.agingtools.utils.SettingUtils;
import com.endoc.agingtools.utils.ToastUtils;


public class SystemSettingActivity extends AppCompatActivity implements View.OnClickListener {
    SystemSettingActivity mContext =this;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_system_setting);

        initView();

    }




    public void initView() {
        findViewById(R.id.bt_close_save_electricity).setOnClickListener(this);
        findViewById(R.id.bt_system_setting).setOnClickListener(this);
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 100 && Activity.RESULT_OK == resultCode) {
            Log.d("onActivityResult", "resultCode==" + resultCode);
            ToastUtils.showToast(mContext,"设置成功");
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.bt_close_save_electricity:
                if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
                    intent.setData(Uri.parse("package:" + this.getPackageName()));
                    startActivityForResult(intent, 100);
                    // isSystemWhiteList(this);
                    // IntentWrapper.whiteListMatters(this,"血糖监测app");
                }
                break;
            case R.id.bt_system_setting:
                SettingUtils.enterWhiteListSetting(this);
                break;
                default:
                    break;
        }
    }



}
